package org.dakuai.graphqldemo;

import org.dakuai.graphqldemo.domain.Author;
import org.dakuai.graphqldemo.domain.Book;
import org.dakuai.graphqldemo.repository.AuthorRepository;
import org.dakuai.graphqldemo.repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class GraphqlDemoApplication implements CommandLineRunner {

	public static void main(String[] args) {
		SpringApplication.run(GraphqlDemoApplication.class, args);
	}

	@Autowired
	private AuthorRepository authorRepository;

	@Autowired
	private BookRepository bookRepository;

	@Override
	public void run(String... args) throws Exception {
		authorRepository.deleteAll();
		bookRepository.deleteAll();

		authorRepository.save(new Author("author-1", "song", "jiang"));
		authorRepository.save(new Author("author-2", "li", "kui"));
		authorRepository.save(new Author("author-3", "wu", "yong"));

		bookRepository.save( new Book("book-1", "Think In Java",  "author-1", 12001));
		bookRepository.save( new Book("book-2", "Think In Python",  "author-2", 234));
		bookRepository.save( new Book("book-3", "Think In C",  "author-3", 1310));

	}
}
